/**
 * Created by Administrator on 2016/3/29.
 */

var SPSdk = (function () {

    var SDK_URL = "http://huhuh5.com:8081/3HGame/jsFile/h5Game.js";
    function SPSdk() {
        this.spId = 0;
        this.appId = "";
        this.appKey = "";
        this.token = "";
        this.spFname = "";
        this.openKey = "";
        this.queryParams = {};
    }

    var __proto = SPSdk.prototype;

    __proto.login = function (param, callback) {
        var m_this = this;
        console.log("虎虎游戏登录：" + JSON.stringify(param));
        h5Game.login("callbackLogin");
       window.callbackLogin = function(userId,userName,userImage,userPosition,token){
            callback && callback({"result":0,"spuid":userId,"nickname":userName});
        }
    }


    __proto.pay = function (param, callback) {
        var m_this = this;
        console.log("虎虎游戏支付：" + JSON.stringify(param));
        var data = param.data;
        var other = data.other;
        var paydata = {goodsName:data.goodsName,orderId:other.orderId+"",money:""+(data.amount/100),goodsNum:"1",ext:other.orderId+""};
        h5Game.pay(paydata,"callbackpay");
        window.callbackpay = function(orderId,status)
        {
            if(status == "SUCCESS")
              callback && callback({"result":0,"desc":status});
            else
                callback && callback({"result":-2,"desc":status});
        }
    }
    __proto.init = function (param, callback) {
        console.log("虎虎游戏初始化：" + JSON.stringify(param));
        var m_this = this;
        LayaCommon.loadScript(SDK_URL, function ()
        {
            m_this.access_token = param.access_token;
            m_this.spId = param.spId;
            m_this.appId = param.appId;
            m_this.spFname = param.spFname;
            m_this.openKey = param.openKey;
            m_this.queryParams = param.queryParams;
            callback && callback({"result": 0, "desc": "OK"});
        });
    }
    return SPSdk;
})();